Skip to content

feat!: complete embedding PyTorch Python API#821

Draft
voltjia wants to merge 1 commit into
masterfrom
feat/complete-embedding-python-api
Draft

feat!: complete embedding PyTorch Python API#821
voltjia wants to merge 1 commit into
masterfrom
feat/complete-embedding-python-api

Conversation

@voltjia

@voltjia voltjia commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add the complete PyTorch Python embedding parameter list while keeping input, weight as the leading tensors.
  • Keep the short default interface and retain the previous full interface as a [[deprecated]] compatibility overload.
  • Implement max_norm/norm_type renormalization for shared CUDA backends and Ascend, and extend the existing test function.

Motivation

#808 restored the two leading tensors but intentionally omitted max_norm and norm_type. InfiniOps should expose the complete public Python contract even though it is a C++ library. This PR adds the missing behavior without multiplying every Python default into another overload.

This is a follow-up to #808; no standalone issue is associated with it.

Type of Change

  • feat - new feature / new operator / new platform
  • fix - bug fix
  • perf - performance improvement (no behavioral change)
  • refactor - code restructuring without behavior change
  • test - adding or fixing tests only
  • docs - documentation only
  • build / ci - build system or CI configuration
  • chore - tooling, formatting, or other non-code changes
  • Breaking change

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

Host: ssh nvidia
Image: accelerator-dev/nvidia:latest
GPU: NVIDIA A100, sm80
PyTorch: 2.10.0a0+b4e4ee8

cmake ... -DWITH_CPU=OFF -DWITH_NVIDIA=ON -DWITH_TORCH=OFF \
  -DCMAKE_CUDA_ARCHITECTURES=80 -DINFINI_OPS_OPS=embedding
cmake --build build-nvidia --target ops -j 16
Build passed.

python -m pytest tests/test_generate_wrappers.py -q
13 passed

python -m pytest tests/test_embedding.py --devices nvidia -q
57 passed

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA Yes targeted build passed 57 cases passed, including legacy and max_norm paths
Iluvatar Yes Not run locally - no Iluvatar host available Uses the changed shared CUDA implementation
MetaX Yes Not run locally - no MetaX host available Uses the changed shared CUDA implementation
Cambricon No N/A - not affected N/A - not affected
Moore Yes Not run locally - no Moore host available Uses the changed shared CUDA implementation
Ascend Yes Not run locally - no Ascend host available Uses aclnnEmbeddingRenorm before aclnnEmbedding

Benchmark / Performance Impact

The default and no-max_norm paths retain the existing lookup kernel. Supplying max_norm adds selected-row norm reduction and in-place weight renormalization, matching PyTorch semantics.

Notes for Reviewers

API alignment

Interface Signature Alignment basis
InfiniOps full embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse, out) Complete PyTorch Python order; explicit out remains last per CONTRIBUTING.md.
InfiniOps short embedding(input, weight, out) Preserves the existing default-use interface without adding prefix overloads.
PyTorch public API F.embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False) Pinned PyTorch source
Deprecated compatibility embedding(input, weight, padding_idx, scale_grad_by_freq, sparse, out) Preserves the #808 full interface for migration.
  • max_norm mutates selected weight rows in place before lookup, following PyTorch native renorm and its CUDA implementation.
  • Ascend uses aclnnEmbeddingRenorm before lookup.
  • padding_idx, scale_grad_by_freq, and sparse affect backward semantics; InfiniOps has no embedding autograd/backward path, so the forward implementation accepts and stores them without changing lookup values.
  • The virtual backend contract gains max_norm and norm_type, which is why the PR is marked feat!; the previous user-facing full call remains available with [[deprecated]].
  • Ruff 0.15.22 and clang-format 21.1.8 checks passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant